package com.zhiwang.planet.mvvm.model.entity

import androidx.room.*
import com.google.gson.annotations.SerializedName
import com.zhiwang.planet.mvvm.model.entity.main.XgUserInfo


data class User(
        @SerializedName("userid")
        var userId: String,
        @SerializedName("username")
        var userName: String,
        @SerializedName("xqlevel")
        var level: String,
        var avatar: String,
        @PrimaryKey
        var phone: String,
        @SerializedName("bind")
        @Embedded
        var bindInfo: BindInfo
) {

    @Ignore
    var token: String = ""

    @Ignore
    @SerializedName("is_wxbind")
    var isBind: Int = 0

    val hasBind: Boolean get() = isBind == 1

    //以下两个字段在首页接口中存在，在登录接口中忽略
    @Ignore
    @SerializedName("gold_z")
    var diamondNumber: String = ""

    @Ignore
    @SerializedName("gold_d")
    var energy: String = ""
}

data class BindInfo(
        @SerializedName("alipay")
        var isAliBind: Boolean,
//        @Ignore
//        @SerializedName("weixinpay")
//        var isWeiXinBind: Boolean,
//        @Ignore
//        @SerializedName("weixinpay_nickname")
//        var weixinNickname: String,
        @SerializedName("alipay_account")
        var aliAccountName: String,
        @SerializedName("alipay_username")
        var aliRealName: String,
        @SerializedName("pay_passwd")
        var hasSetPaypassword: Boolean) {

}


@Dao
interface UserDao {

    @Query("select * from User limit 1")
    fun getFirstUser(): XgUserInfo

    @Update
    fun updateUser(user: XgUserInfo)

    @Update
    fun updateUsers(users: List<XgUserInfo>)

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun addUser(user: XgUserInfo)

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun addUser(users: List<XgUserInfo>)

    @Query("DELETE FROM User")
    fun deleteAll()
}